<?php
/**
 * @package    Joomla.Tutorials
 * @subpackage Components
 * @link http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_1
 * @license    GNU/GPL
*/
 
// no direct access
 
defined( '_JEXEC' ) or die( 'Restricted access' );
 
jimport( 'joomla.application.component.view');
jimport( 'joomla.filesystem.path' );

jimport( 'joomla.database.database' );
 
/**
 * HTML View class for the HelloWorld Component
 *
 * @package    HelloWorld
 */
 
class wotclanViewlisttanks extends JView
{
    function display($tpl = null)
    {
    	if (JFactory::getUser()->authorise('core.add', 'com_wotclan')) 
      {
      include JPATH_COMPONENT.DS.'functions.php';

    	  $greeting = "Les tanks de la DB!";
        $this->assignRef( 'greeting', $greeting );
        parent::display($tpl);
    		 $db =& JFactory::getDbo();
      
      $query = $db->getQuery(true);
      if($_REQUEST["user"] != ""){ 
      	$MYWHERE="WHERE `name`='".$_REQUEST['user']."'";     	
      }
      if ($_REQUEST["clan"] != ""){
      	if ($_REQUEST['clan'] == "SANSCLAN") {$_REQUEST['clan'] = "";}
      //	echo "Request clan est pas null";
      	if ($MYWHERE != ""){
      		
      	//	echo "<br>Request clan est pas null et user est pas null";
      		$MYWHERE=$MYWHERE." AND `clan`='".$_REQUEST['clan']."'";
      		
      	} else {
      	//	echo "<br>Request clan est pas null et user est null";
      		$MYWHERE=" WHERE `clan`='".$_REQUEST['clan']."'";
      	}
      }
      //echo "<br>MYWHERE : ".$MYWHERE;
      $query="SELECT * FROM `#__wotclan_account`";
      if  ($MYWHERE != ""){
      	$query=$query. $MYWHERE;
      }
      $query=$query. " LIMIT 0,50" ;
      $db->setQuery($query);
      $db->query();
      $num_rows = $db->getNumRows();
      $rows = $db->loadObjectList();
      echo "<div align='center'>";
      foreach ( $rows as $row ) {
      	
    		echo "<table><tr><td width='250' align='center' style='border:1px solid white'><a href='?view=listtanks&user=".$row->name."'>".$row->name."</a>";
    		if ($row->clan != ""){
    			echo " [<a href='?view=listtanks&clan=".$row->clan."'>".$row->clan."</a>]";
    		}
    		echo "</td><td width='250' align='center' style='border:1px solid white'>";
    		
    		$tank = explode("|",$row->tanks);
        //echo $row->tanks."<br>";
    		$x=0;
    		
      	while ($tank[$x] != ""){
    		  $query2 = $db->getQuery(true);
    		  $query2="SELECT * FROM `#__wotclan_tanks` WHERE `uniqid`='".$tank[$x]."'";
        //  echo "<br>".$query2."<br>";
    		  $db->setQuery($query2);
      	  $db->query();
      	  $num_rows2 = $db->getNumRows();
      	  $rows2 = $db->loadObjectList();
      	  
        	  if ($num_rows2 == 1){
        	  	showimgtank($rows2[0]->name,$rows2[0]->common_name,$rows2[0]->tanktype,$rows2[0]->uniqid);
			echo '<br>';
      		//	  echo "tanks : ".$rows2[0]->name;
      		    //foreach ( $rows2 as $row2 ) {
      		    //	$tabletank=explode(':',$row2->name);
      		    //$tabletank[0]=$row2->name);
      		    //	if ($tabletank[0] == "france"){
      		    //		echo "<img src='../../../media/mod_languages/images/fr.gif'> ";
      		    //	}	else if ($tabletank[0] == "germany"){
      		    //		echo "<img src='../../../media/mod_languages/images/de.gif'> ";
      		    //	}	else if ($tabletank[0] == "ussr"){
      		    //		echo "<img src='../../../media/mod_languages/images/ru.gif'> ";
      		    //	}	else if ($tabletank[0] == "china"){
      		    //		echo "<img src='../../../media/mod_languages/images/tr.gif'> ";
      		    //	}	else if ($tabletank[0] == "uk"){
      		    //		echo "<img src='../../../media/mod_languages/images/en.gif'> ";
      		    //	}	else if ($tabletank[0] == "usa"){
      		    //		echo "<img src='../../../media/mod_languages/images/us.gif'> ";
      		    //	}	else {
      		    //		echo $tabletank[0]." "; 
      		    //	}
      		  
      			  //	echo $tabletank[1]."<br>";
    			   // }
    			    
                    
                
            } elseif ($num_rows2 == 0) {
            	echo "<tr>Prob avec le tank ".$x."(".$tank[$x].") : aucun tank</tr>";
            } else {
            	echo "<tr>Prob avec le tank ".$x."(".$tank[$x].") : trop de tank</tr>";
            }
        
        
		    $x++;
    		
  		  }
  		echo "</table>";
  	 
			}	
		echo "</div>";

      }
    
    }
}



	
